﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.Data.SqlClient;
public partial class UserAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["flag"] == null)
            {
                Response.Redirect("../../Login.aspx");
            }
            
        }
    }
    protected void btnClickOk_Click(object sender, EventArgs e)
    {
        string UserName = this.txtUserName.Text.Trim();
        string Password = this.txtPassword.Text.Trim();
        string Role = this.ddlRole.SelectedValue.ToString();
        try
        {
                    DB.ExSql("insert into tb_UserInfo  values('" + UserName + "','" + Password + "','" + Role + "')");
                    Response.Write("<script>alert('添加成功！')</script>");
                    this.ddlRole.SelectedIndex = -1;
                    this.txtUserName.Text = "";     //清空文本框
        }
        catch (SqlException oe)
        {
            Response.Write("<script>alert('" + oe.Message.ToString() + "')</script>");
        }
    }
    protected void lnkbtnUserName_Click(object sender, EventArgs e)
    {
        string UserName = this.txtUserName.Text.Trim();
        SqlDataReader sdr = DB.reDr("select * from tb_UserInfo where UserName='"+UserName+"'" );
        sdr.Read();
        if (!sdr.HasRows)
        {
            Response.Write("<script>alert('该用户名没有被使用');location='UserAdd.aspx'</script>");
            this.txtUserName.Text = UserName;
        }
        else
        {
            Response.Write("<script>alert('该用户名已经被使用');location='UserAdd.aspx'</script>");
            this.txtUserName.Text = "";
        }
        sdr.Close();
    }
}
